home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / Compressor.lha / CompressorClass / Examples / Amiga-E / Compi.e < prev    next >
Encoding:
Text File  |  1998-09-23  |  8.7 KB  |  249 lines

  1. /* -- ----------------------------------------------------------------- -- *
  2.  * -- Program.....: Compi.e                                             -- *
  3.  * -- Author......: Daniel Kasmeroglu <raptor@cs.tu-berlin.de>          -- *
  4.  * -- Description.: Shows that you can ignore the XPK-Standard          -- *
  5.  * -- ----------------------------------------------------------------- -- *
  6.  * -- History                                                           -- *
  7.  * --                                                                   -- *
  8.  * --   0.1 (17. September 1998) - Started with writing.                -- *
  9.  * --   1.0 (17. Sepeteber 1998) - Finished writing.                    -- *
  10.  * --                                                                   -- *
  11.  * -- ----------------------------------------------------------------- -- */
  12.  
  13. /* -- ----------------------------------------------------------------- -- *
  14.  * --                              Options                              -- *
  15.  * -- ----------------------------------------------------------------- -- */
  16.  
  17. OPT PREPROCESS       -> enable preprocessor
  18. OPT REG = 5          -> register-optimisation
  19.  
  20.  
  21. /* -- ----------------------------------------------------------------- -- *
  22.  * --                              Modules                              -- *
  23.  * -- ----------------------------------------------------------------- -- */
  24.  
  25. MODULE 'libraries/compressor',
  26.        'libraries/iffparse',
  27.        'libraries/xpk',
  28.        'intuition/classes',
  29.        'utility/tagitem',
  30.        'tools/boopsi',
  31.        'classes/compressor'   -> most users are using "emodules:libraries/" instead
  32.  
  33. MODULE 'lib/compressor'
  34.  
  35.  
  36. /* -- ----------------------------------------------------------------- -- *
  37.  * --                               Main                                -- *
  38.  * -- ----------------------------------------------------------------- -- */
  39.  
  40. ENUM ARG_HELP,
  41.      ARG_HIDE,
  42.      ARG_LOAD,
  43.      ARG_METHOD,
  44.      ARG_MODE,
  45.      ARG_PASSWORD,
  46.      ARG_GUI,
  47.      ARG_SAVE,
  48.      ARG_DECOMPRESS,
  49.      ARG_FILES
  50.  
  51.  
  52. /* -- ----------------------------------------------------------------- -- *
  53.  * --                             Routines                              -- *
  54.  * -- ----------------------------------------------------------------- -- */
  55.  
  56. ->»» PROC main
  57. PROC main()
  58. DEF ma_object      : PTR TO object
  59. DEF ma_class       : PTR TO iclass
  60. DEF ma_files2files : ccmFiles2Files
  61. DEF ma_args        : PTR TO LONG
  62. DEF ma_rdargs,ma_num
  63.  
  64.   ma_args   := [ FALSE, FALSE, NIL, 'HUFF', 50, 'Peter Lustig', FALSE, NIL, FALSE, NIL ]
  65.   ma_rdargs := ReadArgs( {lab_Template}, ma_args, NIL )
  66.   IF ma_rdargs <> NIL
  67.  
  68.     WriteF( '\s\n', {lab_Message} )
  69.     IF ma_args[ ARG_HELP ] = FALSE
  70.  
  71.       compressorbase := OpenLibrary( 'compressor.class', 1 )
  72.       IF compressorbase <> NIL
  73.  
  74.         ma_class := Cc_GetClassPtr()
  75.         IF ma_class <> NIL
  76.  
  77.           ma_object := NewObjectA( ma_class, NIL, [ CCA_INTERNALPROGRESS, TRUE, TAG_END ] )
  78.           IF ma_object <> NIL
  79.  
  80.             -> is there a file to load ?
  81.             IF (ma_args[ ARG_LOAD ] <> NIL) AND (FileLength( ma_args[ ARG_LOAD ] ) > 0) THEN com_Load( ma_object, ma_args[ ARG_LOAD ] )
  82.  
  83.             -> The password should not be visible
  84.             SetAttrsA( ma_object, [ CCA_HIDEPASSWORD , ma_args[ ARG_HIDE ] , TAG_END ] )
  85.  
  86.             -> set the method and the password
  87.             IF ma_args[ ARG_METHOD   ] <> NIL THEN SetAttrsA( ma_object, [ CCA_METHOD       ,       ma_args[ ARG_METHOD   ]  , TAG_END ] )
  88.             IF ma_args[ ARG_PASSWORD ] <> NIL THEN SetAttrsA( ma_object, [ CCA_PASSWORD     ,       ma_args[ ARG_PASSWORD ]  , TAG_END ] )
  89.  
  90.             -> the mode is not 50 (default) it was changed
  91.             -> and a pointer has taken place. small values
  92.             -> cannot be a pointer because such a small
  93.             -> value is preserved for the system.
  94.             IF ma_args[ ARG_MODE ] <> 50
  95.               SetAttrsA( ma_object, [ CCA_MODE, Long( ma_args[ ARG_MODE ] ), TAG_END ] )
  96.             ELSE
  97.               SetAttrsA( ma_object, [ CCA_MODE, 50, TAG_END ] )
  98.             ENDIF
  99.  
  100.             -> call the gui if the user wants that
  101.             IF ma_args[ ARG_GUI ] <> FALSE THEN domethod( ma_object, [ CCM_PREFSGUI ] )
  102.  
  103.             -> save the preferences
  104.             IF ma_args[ ARG_SAVE ] <> NIL THEN com_Save( ma_object, ma_args[ ARG_SAVE ] )
  105.  
  106.             -> if both are FALSE then we don't need to do anything
  107.             IF ma_args[ ARG_FILES ] <> NIL
  108.  
  109.               ma_files2files.methodid         := CCM_FILES2FILES
  110.               ma_files2files.com_Compressing  := IF ma_args[ ARG_DECOMPRESS ] <> FALSE THEN FALSE ELSE TRUE
  111.               ma_files2files.com_Sources      := ma_args[ ARG_FILES ]
  112.               ma_files2files.com_Destinations := NIL
  113.               ma_files2files.com_Results      := NIL
  114.               ma_files2files.com_Suffix       := 'xpk'
  115.  
  116.               ma_num := domethod( ma_object, ma_files2files )
  117.  
  118.               WriteF( '\d files were processed succesfully !\n', ma_num )
  119.  
  120.             ENDIF
  121.  
  122.           ELSE
  123.             WriteF( 'Cannot create object !\n' )
  124.           ENDIF
  125.  
  126.         ELSE
  127.           WriteF( 'Class is not available !\n' )
  128.         ENDIF
  129.  
  130.         CloseLibrary( compressorbase )
  131.       ELSE
  132.         WriteF( 'Cannot open "compressor.class" v1+ !\n' )
  133.       ENDIF
  134.     ELSE
  135.       WriteF( '\s\n', {lab_CLIUsage} )
  136.     ENDIF
  137.     FreeArgs( ma_rdargs )
  138.  
  139.   ELSE
  140.     WriteF( 'Cannot read args ! IoErr() = \d\n', IoErr() )
  141.   ENDIF
  142.  
  143. ENDPROC
  144. ->»»>
  145.  
  146. ->»» PROC com_Load
  147. PROC com_Load( loa_object, loa_file )
  148. DEF loa_sp         : PTR TO storedproperty
  149. DEF loa_buff [ 4 ] : STRING
  150. DEF loa_handle,loa_length
  151.  
  152.   -> stupid function to read the IFF-File
  153.   loa_sp     := [ NIL, 0 ]:storedproperty
  154.   loa_handle := Open( loa_file, OLDFILE )
  155.   IF loa_handle <> NIL
  156.     Read( loa_handle, loa_buff, 4 )
  157.     IF StrCmp( loa_buff, 'FORM', 4 ) <> FALSE
  158.       Read( loa_handle, loa_buff, 4 )
  159.       Read( loa_handle, loa_buff, 4 )
  160.       IF StrCmp( loa_buff, 'CCCP', 4 ) <> FALSE
  161.         Read( loa_handle, {loa_length}, 4 )
  162.         loa_sp.size := loa_length
  163.         loa_sp.data := New( loa_length )
  164.         IF loa_sp.data <> NIL
  165.           IF Read( loa_handle, loa_sp.data, loa_length ) = loa_length
  166.             SetAttrsA( loa_object, [ CCA_PREFSCHUNK, loa_sp, TAG_END ] )
  167.           ENDIF
  168.         ENDIF
  169.       ENDIF
  170.     ENDIF
  171.     Close( loa_handle )
  172.   ELSE
  173.     WriteF( 'Cannot open file "\s" !\n', loa_file )
  174.   ENDIF
  175.  
  176. ENDPROC
  177. ->»»>
  178.  
  179. ->»» PROC com_Save
  180. PROC com_Save( sav_object, sav_file )
  181. DEF sav_sp : PTR TO storedproperty
  182. DEF sav_handle,sav_err,sav_source
  183.  
  184.   -> very simple routine to write a stupid
  185.   -> IFF-file.
  186.  
  187.   GetAttr( CCA_PREFSCHUNK, sav_object, {sav_sp} )
  188.   sav_err    := FALSE
  189.   sav_handle := Open( sav_file, NEWFILE )
  190.   IF sav_handle <> NIL
  191.     sav_source := ID_FORM
  192.     IF Write( sav_handle, {sav_source}, 4 ) = 4
  193.       sav_source := sav_sp.size + 8
  194.       IF Write( sav_handle, {sav_source}, 4 ) = 4
  195.         sav_source := ID_CCCP
  196.         IF Write( sav_handle, {sav_source}, 4 ) = 4
  197.           sav_source := sav_sp.size
  198.           IF Write( sav_handle, {sav_source}, 4 ) = 4
  199.             IF Write( sav_handle, sav_sp.data, sav_sp.size ) <> sav_sp.size
  200.               sav_err := TRUE
  201.             ENDIF
  202.           ELSE
  203.             sav_err := TRUE
  204.           ENDIF
  205.         ELSE
  206.           sav_err := TRUE
  207.         ENDIF
  208.       ELSE
  209.         sav_err := TRUE
  210.       ENDIF
  211.     ELSE
  212.       sav_err := TRUE
  213.     ENDIF
  214.     Close( sav_handle )
  215.   ENDIF
  216.  
  217.   IF sav_err <> FALSE THEN DeleteFile( sav_file )
  218.  
  219. ENDPROC
  220. ->»»>
  221.  
  222.  
  223. /* -- ----------------------------------------------------------------- -- *
  224.  * --                               Data                                -- *
  225.  * -- ----------------------------------------------------------------- -- */
  226.  
  227. lab_Template:
  228. CHAR '?/S,H=HIDEPASSWORD/S,L=LOAD/K,M=METHOD/K,O=MODE/K/N,P=PASSWORD/K,GUI/S,S=SAVE/K,D=DECOMPRESS/S,FILES/M',0
  229.  
  230. lab_Message:
  231. CHAR '\e[1;1mCompi 1.0 (c) \a98 \e[2mDaniel Kasmeroglu\e[0m',0
  232.  
  233. lab_CLIUsage:
  234. CHAR '\n    \e[2;2mCLI-Parameter        Description\e[0;0m\n\n',
  235.      '     ?            /S   : This description\n',
  236.      ' H = HIDEPASSWORD /S   : The password in the gui will be replaced by wildcards\n',
  237.      ' L = LOAD         /K   : Specify the path of the prefsfile to load\n',
  238.      ' M = METHOD       /K   : The method you want to use (compression only)\n',
  239.      ' O = MODE         /K/N : The mode you want to use (compression only)\n',
  240.      ' P = PASSWORD     /K   : The password you want to use\n',
  241.      '     GUI          /S   : Pops up the gui before saving or (de)compressing\n',
  242.      ' S = SAVE         /K   : Specify the path of the prefsfile to save\n',
  243.      ' D = DECOMPRESS   /S   : Decompress the listed files (default is compression)\n',
  244.      '     FILES        /M   : List with the files that should be processed !\n',0
  245.  
  246. lab_Version:
  247. CHAR '$VER: Compi 1.0 (17-Sep-98) [ Daniel Kasmeroglu ]',0
  248.  
  249.